import requests
import lxml
from pyquery import PyQuery as pq

url = 'http://localhost:8888/shopxo/'

# 初始化方法一： URL方式初始化
response = requests.get(url)
html_content = response.text

# 字符串方式初始化
doc = pq(html_content)


# print(doc)

#初始化方法二： URL方式初始化； 简单的网站可以使用此方法
# doc = pq(url)
# print(doc)

# 初始化方法三：文件方式初始化
# doc = pq(filename='shopxo.html')
# print(doc)



# 节点操作
# print(doc('.goods-list').siblings())
# print(doc('.banner-news ul li a').attr('href'))
#
# 遍历
# links = doc('.banner-news ul li a')
# for item in links.items():
#     # print(type(item))
#     # print(item.attr('href'))
#     # item('span').html('<p>大熊课堂</p>')
#     item('span').remove()
#     print(item)

# 使用伪类
news_list = doc('.banner-news ul li:nth-child(2n)')
print(news_list)
